module.exports = function ($resource, $state, $http, $q, FileUploader, $modal, toaster, $stateParams) {
  
	return {
		restrict: 'AE',
		template: require('../views/planningnotice.html'),
		replace: true,
		scope: {
			'baseinfo': '=',
			'examineflag' : '='
		},
		link: function (scope, elements, attrs) {
			scope.type = $stateParams.type;
      scope.info = {};
      var paras = {};
      var url = '';
      if (scope.type == '0'){
				url = '/api/as/ggc/reviewGuide/findInfoDivisionList';
        apiurl = '/api/as/ggc/reviewGuide/updateDivisionUp';
      } else if(scope.type == '1'){
				url = '/api/as/ggc/reviewGuide/findInfoDirectorsList'
        apiurl = '/api/as/ggc/reviewGuide/updateDivisionsUp ';
        paras = {
          guide_state : '2'
        }
      } else if(scope.type == '2'){
				url = '/api/as/ggc/reviewGuide/findInfoImporpantList'
        apiurl = '/api/as/ggc/reviewGuide/updateImporpantUp ';
        paras = {
          guide_state : '4'
        }
      }
			/* 分页
			* ========================================= */
			scope.maxSize = 5;             //最多显示多少个按钮
			scope.bigCurrentPage = 1;      //当前页码
      scope.itemsPerPage = 10         //每页显示几条
      scope.obj={};
      scope.d={};
      scope.searchform = {};

			
			scope.getlist = function (state) {
				var para = {
					pageNo:scope.bigCurrentPage, 
          pageSize:scope.itemsPerPage
        };
        console.log(state);
        if (state == undefined || state == '') { //正常加载 
				  para = angular.extend(paras, para, scope.searchform);
        } else {
            if (scope.type == '1') { // 主管领导
              var para1 = {
                deputy_director_state : state,
              }
              para = angular.extend(para, scope.searchform, para1);
            } else if (scope.type == '2'){ // 主要领导
              var para1 = {
                leader_audit_state : state,
              }
              para = angular.extend(para, scope.searchform, para1);
            }
        }
				
				// para = angular.extend(scope.searchform, para);
				$resource(url, {}, {}).
				save(para,function(res) {
					console.log(para);
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					console.log('上面是认定公告返回值');
					scope.objs = res.data.results;
					scope.bigTotalItems = res.data.totalRecord;				
					// angular.forEach(scope.objs,function(item){
					// 	if(item.project_level == '0'){
					// 		item.project_level = '区县'
					// 	}
					// 	if(item.project_level == '1'){
					// 		item.project_level = '市'
					// 	}
					// 	if(item.project_level == '2'){
					// 		item.project_level = '省'
					// 	}
					// 	if(item.project_level == '30'){
					// 		item.project_level = '国家'
					// 	}
					// })	
				})
			};
			
			scope.getlist(); 

			// scope.$watch('examineflag', function(){
			// 	scope.getlist();
			// }, true)
			
			// scope.getlist(); 

			scope.pass = function(info) {
				if(confirm('确认要通过吗？')==true){
				$resource(apiurl, {}, {}).
				save({'id':info.id},function(res) {
					if (res.errcode != 0) {
						toaster.error({title:"通过失败",body:res.errmsg});
						return;
					} else {
						toaster.success({title:"通过成功",body:res.errmsg});
						scope.getlist();
					}
				});
			}
			}
			scope.back= function (info) {
        scope.flag = 'ggbohui'
				var modalInstance = $modal.open({
					template: require('../views/reject_notice.html'),
					controller: 'reject_notice',
					size: 'xs',
					resolve: {
						info: function () {
							return info;
            },
            flag: function () {
							return scope.flag;
						}
					}
				});
				// modalInstance.result.then(function (showResult) {	
        //   scope.examineflag++;
				// });
				//关闭模态框刷新页面
			modalInstance.result.then(function() {
				scope.getlist();
			});
			}
			scope.toinfo = function (info) {
				console.log(info);
				info.flag = '1';
				var modalInstance = $modal.open({
					template: require('../views/noticeinfo.html'),
					controller: 'noticeinfo',
					size: 'lg',
					resolve: {
						items: function () {
							return info;
						}
					}
				});
				// modalInstance.result.then(function (showResult) {	
        //   scope.examineflag++;
				// });
				//关闭模态框刷新页面
				modalInstance.result.then(function() {
					$scope.getlist();
				});
			}


    }
	}
}